<!-- 我的客户 -->
<template>
	<loading-page v-if="showSkeleton" />
	<!-- list -->
	<view class="list">
		<template v-for="(item,index) in dataList" :key="index">
			<list-customer-item type="hall" :autoSend="data.autoSend" :item="item" @changeStatus="changeStatus" />
		</template>
	</view>
	<!-- 无数据 -->
	<empty v-if="!dataList.length&&!showSkeleton" />
	<!-- 更多数据 -->
	<uni-load-more :status="loadMore.status" v-if="loadMore.show" :contentText="loadMore.txt"></uni-load-more>
</template>
<script setup>
	import { reactive, defineComponent, watch } from 'vue';
	import { onReachBottom, onUnload, onPullDownRefresh } from '@dcloudio/uni-app';
	import useGetList from '@/common/hooks/useGetList.js';
	import listCustomerItem from '../components/list-customer-item.vue';
	import useCheck from '../components/useCheck.js';
	defineComponent({
		listCustomerItem
	});
	onReachBottom(() => {
		reachBottom();
	});
	onPullDownRefresh(() => {
		pullDownRefresh();
	});
	onUnload(() => {
		clearTime();
	});
	const { getDataList, dataList, page, loadMore, showSkeleton, reachBottom, pullDownRefresh } = useGetList();
	const { checkContinue, checkRefresh, checkForbid, changeBtnsStatus, clearTime } = useCheck();
	const defaultParams = {};
	const data = reactive({
		searchParams: defaultParams,
		autoSend: 1
	});
	// 初始化数据
	async function init(showLoading = false) {
		const res = await getDataList({
			url: '/crm/Custom/hall',
			params: {
				...data.searchParams
			},
			showLoading: showLoading,
			key: 'lists'
		});
		// 列表状态检测
		if (dataList.value.length) checkContinue(dataList.value, 'hall');
		// 检测是否禁用功能
		checkForbid(res);
		// 检测刷新
		checkRefresh(() => {
			pullDownRefresh();
		});
		data.autoSend = res.defaultgreetings;
	}
	init();
	watch(dataList, (newVal) => {
		if (newVal) {
			dataList.value.forEach(item => {
				item.contact_status = 0;
			})
		}
	})
	// 改变状态
	function changeStatus(o) {
		changeBtnsStatus(o, dataList.value);
	}
</script>
<style lang="scss">
	@import '@/common/css/base.scss';
	page {
		background-color: $bgColor;
	}
</style>
<style scoped lang="scss">
	.list {
		padding: 0 28rpx;
	}
</style>
